
#ifndef ILI9341_STM32_DRIVER_H
#define ILI9341_STM32_DRIVER_H

#include "main.h"
#include "stm32h7xx_hal.h"
#include <stdbool.h>
#include "color.h"
#include <stdlib.h>


#define ILI9341_SCREEN_HEIGHT 240 
#define ILI9341_SCREEN_WIDTH 	320
#define BURST_MAX_SIZE 1024 // 假设的默认缓冲区大小，可以根据需要调整



//SPI INSTANCE
#define HSPI_INSTANCE							&hspi1

#define LCD_CS_H()		LCD_CS_GPIO_Port->BSRR = LCD_CS_Pin;
#define LCD_CS_L()		LCD_CS_GPIO_Port->BSRR = (uint32_t)LCD_CS_Pin << (16U);

#define LCD_DC_H()		LCD_DC_GPIO_Port->BSRR = LCD_DC_Pin;
#define LCD_DC_L()		LCD_DC_GPIO_Port->BSRR = (uint32_t)LCD_DC_Pin << (16U);









#define SCREEN_VERTICAL_1			0   
#define SCREEN_HORIZONTAL_1		    1     
#define SCREEN_VERTICAL_2			2
#define SCREEN_HORIZONTAL_2		    3

void ILI9341_SPI_Init(void);        //初始化SPI
void ILI9341_SPI_Send(unsigned char SPI_Data);





void ILI9341_Write_Command(uint8_t Command);    //写入命令
void ILI9341_Write_Data(uint8_t Data);         //写入数据
void ILI9341_Set_Address(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2);//设置地址
void ILI9341_Reset(void);                      //复位
void ILI9341_Set_Rotation(uint8_t Rotation);    //设置旋转
void ILI9341_Disable(void);                    //关闭
void ILI9341_Enable(void);                     //开启   
void ILI9341_Init(void);                        //初始化
void ILI9341_Set_Brightness(uint8_t Brightness); //设置亮度

void ILI9341_Fill_Screen(uint16_t Colour);          //填充屏幕



void ILI9341_Draw_Colour(uint16_t Colour);       //绘制颜色
void ILI9341_Draw_Pixel(uint16_t X,uint16_t Y,uint16_t Colour);     //绘制像素
void ILI9341_Draw_Colour_Burst(uint16_t Colour, uint32_t Size); //绘制颜色

// void ILI9341_Draw_Colour_Burst(uint16_t Colour, uint32_t Size);             //绘制颜色
void ILI9341_Draw_Rectangle(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Height, uint16_t Colour);    //绘制矩形
void ILI9341_Draw_Horizontal_Line(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Colour);  //绘制水平线
void ILI9341_Draw_Vertical_Line(uint16_t X, uint16_t Y, uint16_t Height, uint16_t Colour);   //绘制垂直线


void ILI9341_Draw_Rectangle(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Height, uint16_t Colour);
void ILI9341_Draw_Horizontal_Line(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Colour);
void ILI9341_Draw_Vertical_Line(uint16_t X, uint16_t Y, uint16_t Height, uint16_t Colour);
	

void ILI9341_Draw_Line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t colour); //绘制线
void ILI9341_Fill_Rectangle_Efficient(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t Colour); //填充矩形


#endif

